package com.my.study.exception;

import com.my.study.entity.vo.ResponseVO;
import com.my.study.enums.BusinessExceptionEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ControllerExceptionHandler {

    @ExceptionHandler({RuntimeException.class, Throwable.class})
    public ResponseVO runtimeException(RuntimeException exception) {
        exception.printStackTrace();
        return ResponseVO.fail(Integer.parseInt(BusinessExceptionEnum.SYSTEM_ERROR.code), exception.getMessage());
    }

    @ExceptionHandler(BusinessException.class)
    public ResponseVO businessException(RuntimeException exception) {
        return ResponseVO.fail(Integer.parseInt(BusinessExceptionEnum.FAIL.code), exception.getMessage());
    }
}
